#include <cctype>
#include <cstdio>
using namespace std;

int n,fu_ke[1010];
char op[10];
bool fu[1010];
long long int a[1010],b[1010],c[1010],d[1010],e[1010];

int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for (int i = 1;i <= n;i++){
		scanf("%s",&op);
		while (!isalpha(op[0])) scanf("%s",&op);
		scanf("%n.%n.%n.%n:%n",&a[i],&b[i],&c[i],&d[i],&e[i]);
		if (op[0] == 'S'){
			fu[i] = true;
			printf("OK\n");
		}
		else if (i == 1){
			printf("FAIL\n");
		}
		else{
			for (int j = 1;j <= i;j++){
				if if (j == i){
					printf("FAIL\n");
					break;
				}
				if (fu[j] && a[i] == a[j] && b[i] == b[j] && c[i] == c[j] && d[i] == d[j] && e[i] == e[j]){
					printf("%d\n",i);
					break;
				}
				
			}
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
